package com.situ.day08;

import org.junit.Test;

public class TestString {

	@Test
	public void test1() {
		String str1 = "abc";
		String str2 = new String("abc");
		String str3 = "abc";
		System.out.println(str1 == str2);// false
		System.out.println(str1 == str3);// true
		System.out.println(str2 == str3);// false
	}

	@Test
	public void test2() {
		String str = "java AndroidA";
		char[] array = str.toCharArray();
		char ch = str.charAt(5);
		System.out.println(ch);// A

		System.out.println(str.indexOf('A'));// 5
		System.out.println(str.indexOf('X'));// -1
		System.out.println(str.indexOf('A', 6));// 12
		System.out.println(str.indexOf("And"));// 5

		System.out.println(str.lastIndexOf('A'));// 12
	}

	@Test
	public void test3() {
		String str = "java AndroidA";
		System.out.println(str.contains("And"));// true
		System.out.println(str.startsWith("java"));// true
		System.out.println(str.startsWith("And", 5));// true
		System.out.println(str.endsWith("oidA"));// true
		System.out.println(str.isEmpty());// false
		System.out.println("".isEmpty());// true
	}

//	
	@Test
	public void test00() {
		String str = "-ass";
		int start = 0;
		int end = str.length() - 1;
		if (str == null || str.equals("")) {
			return;
		}
		while (start <= end && str.charAt(start) == '-') {
//			if (start == str.length() - 1) {
//				break;
//			}
			start++;
		}
		while (start <= end && str.charAt(end) == '-') {
//			if (end == start) {
//				break;
//			}
			end--;
		}
		if (start == str.length()) {
			System.out.println("全是空格");
		} else {
			String str2 = str.substring(start, end + 1);
			System.out.println(str2);

		}
	}

	@Test
	public void test11() {
		String str = "I Love Java！";
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
				str = str.replace(str.charAt(i), (char) (str.charAt(i) + 32));
			}
		}
		System.out.println(str);
	}

	@Test
	public void test22() {
		String str = "this is my homework! I must finish it!";
		String[] arrays = str.split(" ");
		System.out.println(arrays.length);
	}
}